package googleearthdownloader;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;

import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.Scrollable;

public class ScrollableImage extends JLabel implements Scrollable, MouseMotionListener {

	
	
	private int deltaMouseX, deltaMouseY ,mouseOldX, mouseOldY ,currentViewportX,currentViewportY;
	
	JScrollPane jsp;
 
	public ScrollableImage() {
		super();
		setAutoscrolls(true); //enable synthetic drag events
		addMouseMotionListener(this); //handle mouse drags
	}
	
	@Override
	public void mouseDragged(MouseEvent e) {
		//The user is dragging us, so scroll!
		/*
		deltaMouseX = e.getXOnScreen()-mouseOldX;
		deltaMouseY = e.getYOnScreen()-mouseOldY;
		
		deltaMouseX= deltaMouseX/16;
		deltaMouseY= deltaMouseY/16;
		
		currentViewportX=mouseOldX+deltaMouseX;
		currentViewportY=mouseOldY+deltaMouseY;
		*/
		//System.out.println(currentViewportX);
		//System.out.println(currentViewportY);
		//Rectangle r = new Rectangle(currentViewportX, currentViewportY,1, 1);
		Rectangle r = new Rectangle(e.getX(), e.getY(),1, 1);
		//Rectangle r = new Rectangle(e.getX(), e.getY(),50, 50);
		//System.out.println("lalala");
		scrollRectToVisible(r);
		

		//mouseOldX=currentViewportX;
		//mouseOldY=currentViewportY;
		
		
		
		
	}
	@Override
	public void mouseMoved(MouseEvent e) {
		/*mouseOldX=e.getXOnScreen();
		mouseOldY=e.getYOnScreen();
		*/
		/*mouseOldX=e.getX();
		mouseOldY=e.getY();*/
	}

	@Override
	public Dimension getPreferredScrollableViewportSize() {
		// TODO Auto-generated method stub
		return getPreferredSize();
	}

	@Override
	public int getScrollableBlockIncrement(Rectangle arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean getScrollableTracksViewportHeight() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean getScrollableTracksViewportWidth() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int getScrollableUnitIncrement(Rectangle arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub
		return 0;
	}

}